package org.example.elm_springboot.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.example.elm_springboot.po.Cart;
import org.example.elm_springboot.service.CartService;

@RestController
@RequestMapping("/cart")
@CrossOrigin(origins = "http://localhost:5174", allowCredentials = "true")
public class CartController {
    
    @Autowired
    private CartService cartService;
    
    @GetMapping("/listCart")
    public List<Cart> listCart(String userId, Integer businessId) {
        return cartService.listCart(userId, businessId);
    }
    
    @PostMapping("/saveCart")
    public int saveCart(Cart cart) {
        cart.setQuantity(1);
        return cartService.saveCart(cart);
    }
    
    @PostMapping("/updateCart")
    public int updateCart(Cart cart) {
        return cartService.updateCart(cart);
    }
    
    @PostMapping("/removeCart")
    public int removeCart(String userId, Integer businessId) {
        return cartService.removeCart(userId, businessId);
    }
} 